{% import "label_system/dropdown_macro.html.twig" as dropdown %}

{% if is_granted('edit', part) %}
    <a href="{{ entity_url(part, 'edit') }}" class="btn btn-primary mt-3">
        <i class="fas fa-fw fa-edit"></i>
        {% trans %}part.edit.btn{% endtrans %}
    </a>
{% endif %}

{# Create new button #}
{% if is_granted('create', part) %}
    <br>
    <div class="btn-group mt-2">
        <a class="btn btn-primary" href="{{ entity_url(part, 'clone') }}">
            <i class="fas fa-clone"></i>
            {% trans %}part.clone.btn{% endtrans %}
        </a>
        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">
            <span class="caret"></span>
        </button>
        <div class="dropdown-menu" role="menu">
            <a class="dropdown-item" href="{{ entity_url(part, 'create') }}">
                <i class="fas fa-plus-square"></i>
                {% trans %}part.create.btn{% endtrans %}
            </a>
        </div>
    </div>
{% endif %}

{# Merge modal #}
{% include "parts/info/_merge_modal.html.twig" %}

{# Update part from info provider button #}
{% if is_granted('edit', part) and is_granted('@info_providers.create_parts') %}
    <br>
    <a class="btn btn-info mt-2" href="{{ path('info_providers_update_part_search', {'target': part.iD}) }}">
        <i class="fas fa-cloud-arrow-down"></i>
        {% trans %}part.update_part_from_info_provider.btn{% endtrans %}
    </a>
{% endif %}


<form method="post" class="mt-2" action="{{ entity_url(part, 'delete') }}"
        {{ stimulus_controller('elements/delete_btn') }} {{ stimulus_action('elements/delete_btn', "submit", "submit") }}
      data-delete-title="{% trans with {'%name%': part.name|escape }%}part.delete.confirm_title{% endtrans %}"
      data-delete-message="{% trans %}part.delete.message{% endtrans %}">
    <input type="hidden" name="_method" value="DELETE">
    <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ part.id) }}">
    <div class="form-group">
        <div class="btn-group">
            <button class="btn btn-danger" {% if not is_granted("delete", part) %}disabled{% endif %}>
                <i class="fa fa-trash fa-fw"></i>
                {% trans %}part.delete{% endtrans %}
            </button>
            <button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="visually-hidden">Toggle Dropdown</span>
            </button>
            <div class="dropdown-menu p-2">
                <div class="form-group"><label for="delete_log_comment">{% trans %}edit.log_comment{% endtrans %}</label>
                    <input type="text" id="delete_log_comment" name="log_comment" class="form-control"
                    {% if event_comment_needed('part_delete') %}required{% endif %}
                    >
                </div>
            </div>
        </div>
    </div>
</form>

{{ dropdown.profile_dropdown('part', part.id) }}

<a class="btn btn-success mt-2" {% if not is_granted('@projects.edit') %}disabled{% endif %}
   href="{{ path('project_add_parts_no_id', {"parts": part.id, "_redirect":  uri_without_host(app.request)}) }}">
    <i class="fa-solid fa-magnifying-glass-plus fa-fw"></i>
    {% trans %}part.info.add_part_to_project{% endtrans %}
</a>